export function createDecorator(factory) {
  return (target, key, index) => {
      const Ctor = typeof target === 'function'
          ? target
          : target.constructor;
      if (!Ctor.__decorators__) {
          Ctor.__decorators__ = [];
      }
      if (typeof index !== 'number') {
          index = undefined;
      }
      Ctor.__decorators__.push(options => factory(options, key, index));
      // factory(target, key, index)
  };
}

export function On(tag, options) {
  options = Object.assign({}, options || {})
  return createDecorator(function(target, key, index) {
    target.on && target.on( tag , target[key]?.bind( target) )
  })
}